package temporay;


import temporay.worker.WorkerService;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.util.ArrayList;
import java.util.List;

/**
 * program: io-share 
 * author: bsworld.xie 
 * create: 2021-04-19 11:27 
 * description: 
 */
public class Reactor {
    public static void main(String[] args) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.configureBlocking(false);
        serverSocketChannel.bind(new InetSocketAddress("127.0.0.1", 5888));
        //读写IO线程
        List<SelectorThread> selectorThreads = new ArrayList<>(10);
        //业务线程
        WorkerService workPool = new WorkerService(20);
        for (int i = 0; i < 10; i++) {
            SelectorThread selectorThread = new SelectorThread(i, workPool);
            selectorThreads.add(selectorThread);
            selectorThread.start();
        }

        AcceptorThread acceptorThread = new AcceptorThread(serverSocketChannel, selectorThreads);
        //启动接收客户端连接
        acceptorThread.start();

    }


}
